<?php
 
/*
 * Following code will list all the products
 */
 
// array for JSON response
$response = array();

if (isset($_POST['user_id_zing'])){
	
	$user_id_zing = $_POST['user_id_zing']; 
 
	// include db connect class
	require_once __DIR__ . '/db_connect.php';
	 
	// connecting to db
	$db = new DB_CONNECT();
	 
	// get all products from products table

	$result = mysql_query("SELECT p.place_name, p.address, p.url_avatar, p.name_avatar, d.name as district_name, 
								pr.name as province_name,u.user_name_zing, c.* 
							FROM comment c
							INNER JOIN 	place p
								ON c.place_id = p.place_id
							INNER JOIN user u
								ON c.user_id_zing = u.user_id_zing
							LEFT JOIN district d
								ON p.district_id = d.id
							LEFT JOIN province pr
								ON pr.id = d.province_id
							WHERE c.user_id_zing = '$user_id_zing'
							ORDER BY c.comment_id desc") or die(mysql_error());
							
	 
	// check for empty result
	if (mysql_num_rows($result) > 0) {
		// looping through all results
		// products node
		$response["comment"] = array();
	 
		while ($row = mysql_fetch_array($result)) {
			// temp user array
			$comment = array();    
		
		$comment["comment_id"] = $row['comment_id'];
		$comment["user_name_zing"] = $row['user_name_zing'];
		$comment["place_id"] = $row['place_id'];
		$comment["place_name"] = $row['place_name'];
		$comment["address"] = $row['address'];
		$comment["province_name"] = $row['province_name'];	
		$comment["district_name"] = $row['district_name'];
		$comment["url_avatar"] = $row['url_avatar'];
		$comment["name_avatar"] = $row['name_avatar'];
		$comment["detail_comment"] = $row['detail_comment'];
		$comment["time_comment"] = $row['time_comment'];
		$comment["type"] = $row['type'];
	 
			// push single product into final response array
			array_push($response["comment"], $comment);
		}
		// success
		$response["success"] = 1;
	 
		// echoing JSON response
		echo json_encode($response);
	} else {
		// no products found
		$response["success"] = 0;
		$response["message"] = "No products found";
	 
		// echo no users JSON
		echo json_encode($response);
	}
} else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";
 
    // echoing JSON response
    echo json_encode($response);
}
?>